﻿@model KRM.Core.tblKRWSuperCategory
@using KRM.Core;
@{
    var db = (KRMEntities)ViewBag._db;
}
<script type="text/javascript">
   
    $(document).ready(function() {
        $('#fr-savewebsite').submit(function () {
            if (confirm("are you sure save change?")) {
                App.blockUI($('body'));
                $.ajax({
                    url: "/products/SaveWebsite",
                    data: $(this).serialize(),
                    success: function (data) {
                        var  showDisplayName = $('#showDisplayName').is(":checked") ? true : false;
                        var   storeId = $('#StoreId').val();
                      
                        var cateID = document.getElementsByName('categoryID')[0].value;
                        $.ajax({

                            url: "/Products/" + $('#activedetail').val() + "?storeId=" + storeId + "&showDisplayName=" + showDisplayName,
                            success: function (data1) {
                                $('#listviewcategory').html(data1.listData);
                                ShowCateDetail(cateID, data1.storeID);
                                $('#listviewcategory tr#' + cateID).addClass('row-selected');
                            }
                        });
                         alert(data.message);
                        App.unblockUI($('body'));
                    },
                    error: function () {
                        App.unblockUI($('body'));
                    }
                });
                App.unblockUI($('body')); 
            }
            return false;
        }); 
        

      
    });
</script>

<form action="/Products/SaveWebsite" method="post" id="fr-savewebsite" class="margin0">
    <div class="row-fluid">

        <div class="span2">Cat ID: @Model.categoryID </div>
        <div class="span7">

            <label>
                @Html.CheckBox("displayed", (bool)ViewBag.Checked, new { @class = "cbcheck" })
                Display
            </label>
        </div>
        <div class="span3 text-right">
            @Html.DropDownList("DefaultSortOrder", null, new { @class = "input-block-level" })
        </div>
    </div>
    <div class="row-fluid">
        <div class="span2">Category Name</div>
        <div class="span5">
            <input type="text" name="categoryName" class="input-block-level" value="@Model.categoryName" />
        </div>
        <div class="span2">Category Image</div>
        <div class="span3">
            <input type="text" class="input-block-level" name="catImage" value="@Model.catImage" />
        </div>
    </div>

    <div class="row-fluid">
        <div class="span12">
            Description
        <textarea name="catDescription" class="input-block-level">@Model.catDescription</textarea>
        </div>
    </div>
    <ul class="tabs tabs-inline tabs-top orderdetail-task-tabs margin0">
        <li class="active"><a href="#detail">Detail</a></li>
        <li><a href="#products">Products</a></li>
    </ul>
    <div class="tab-content padding tab-content-inline tab-content-bottom orderdetail-task-tabs-content modal-scrollable">
        <div id="detail" class="tab-pane active">
            <input type="hidden" id="CategoryStoreID" name="CategoryStoreID" value="@ViewBag.CategoryStoreID" />
            <input type="hidden" name="StoreID" value="@ViewBag.StoreID" />
            <input type="hidden" id="categoryID" name="categoryID" value="@Model.categoryID" />
            <div class="row-fluid">
                <div class="span4">
                    <div class="fieldset">
                        <div class="legend"><span>Website(s) of Category</span> </div>

                        <div class="row-fluid overflow-auto tb-cateDetail" style="height: 100px">
                            <div class="span12">
                                <table class="table table-bordered table-fix tbl-selected krmtable" data-height="270">
                                    <tbody id="twebsite">
                                        @foreach (var item in (List<tblKRWSuperCategoryStore>)@ViewBag.Website)
                                        { 
                                            <tr style="cursor: pointer" onclick="CurrentStore('@item.StoreID');LoadSuperCateByWebsite('@item.StoreID','@Model.categoryID'); ">
                                                <td>@db.tblStores.Find(item.StoreID).StoreName</td>
                                            </tr>
                                        }
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="span3">Url</div>
                            <div class="span9">
                                <input type="text" class="input-block-level" required="required" name="categoryRewrite" value="@ViewBag.categoryRewrite" />
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="span3">Name</div>
                            <div class="span9">
                                <input type="text" class="input-block-level" required="required"name="displayName" value="@ViewBag.displayName" />
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="span12">
                                <input type="button" class=" btn-remove" name="name" value="" onclick="RemoveWebsite()" />
                                <input type="button" class=" btn-add" name="name" value="" onclick="PopupCenter('/products/OpenWebsites?cateID=@Model.categoryID    ',350,500)" />
                            </div>

                        </div>
                    </div>
                </div>
                <div class="span4">
                    <div class="fieldset">
                        <div class="legend"><span>Parent Cat(s)</span> </div>
                        <div class="row-fluid overflow-auto tb-cateDetail">
                            <div class="span12">
                                <input type="hidden" name="parentCateID" value="" />
                                <table class="table table-bordered table-fix tbl-selected krmtable" data-height="270">
                                    <tbody id="tparentcate">
                                        @foreach (var item in (List<tblKRWSuperCategory>)@ViewBag.dgvParentCats)
                                        { 
                                            <tr style="cursor: pointer" onclick="CurrentCateParent('@item.categoryID');" >
                                                <td>@item.categoryName</td>
                                            </tr>
                                        }
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="span12">
                                <input type="button" class=" btn-remove" name="name" value="" onclick="RemoveParentCate()" />
                                <input type="button" class=" btn-add" id="btnAddParentCat" name="name" value="" />
                            </div>

                        </div>
                    </div>
                </div>
                <div class="span4">
                    <div class="fieldset">
                        <div class="legend"><span> Child Cat(s)</span></div>
                        <div class="row-fluid overflow-auto tb-cateDetail ">
                            <div class="span12">
                                <input type="hidden" name="childCateID" value="" />
                                <table class="table table-bordered table-fix tbl-selected krmtable" data-height="270">
                                    <tr>
                                        <th>Position</th>
                                        <th>CategoryName</th>
                                    </tr>
                                    <tbody id="tchildcate">
                                        @{
                                            int d = ((List<tblKRWSuperCategory>)@ViewBag.dgvChildCats).Count;
                                            foreach (var item in (List<tblKRWSuperCategory>)@ViewBag.dgvChildCats)
                                            {  <tr style="cursor: pointer" onclick="CurrentChildCate('@item.categoryID');" >
                                                <td>@d  </td>
                                                <td>@item.categoryName</td>
                                            </tr>
                                                d--;
                                            }}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="span12">
                                <input type="button" class=" btn-remove" name="name" value="" onclick="RemoveChildCate()" />
                                <input type="button" class=" btn-add" name="name" id="btnAddChildCat" value="" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <ul class="tabs tabs-inline tabs-top orderdetail-task-tabs margin0" id="ulmeta">
                <li class="active"><a href="#meta">Meta</a></li>
                <li><a href="#customblocks">Custom Blocks</a></li>
            </ul>
            <div class="tab-content padding tab-content-inline tab-content-bottom orderdetail-task-tabs-content modal-scrollable" id="divmeta">
                <div id="meta" class=" tab-pane active">
                    <div class="row-fluid">
                        <div class="span2">Title</div>
                        <div class="span10">
                            <input type="text" name="MetaPageTitle" class="input-block-level"  value="@ViewBag.MetaPageTitle" />
                        </div>
                    </div>
                    <div class="row-fluid">
                        <div class="span2">Description</div>
                        <div class="span10">
                            <textarea class="input-block-level" name="MetaDescription">@ViewBag.MetaDescription</textarea>
                        </div>
                    </div>
                    <div class="row-fluid">
                        <div class="span2">Keywords</div>
                        <div class="span10">
                            <textarea class="input-block-level" name="MetaKeywords">@ViewBag.MetaKeywords</textarea>
                        </div>
                    </div>
                </div>
                <div id="customblocks" class=" tab-pane ">
                    <div class="row-fluid">
                        <div class="span2">Block 1</div>
                        <div class="span10">
                            <textarea class="input-block-level" name="CustomBlock">@ViewBag.CustomBlock</textarea>
                        </div>
                    </div>
                    <div class="row-fluid">
                        <div class="span2">Block 2</div>
                        <div class="span10">
                            <textarea class="input-block-level" name="CustomBlock2">@ViewBag.CustomBlock2</textarea>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <div id="products" class="tab-pane">
            <div class="row-fluid">
                <div class="span6">
                    <input type="text" name="filter" id="filter" value="" class="input-block-level" />
                </div>
                <div class="span2">
                    <input type="button" name="name" class="btn btn-gray" value="Search" id="searchproduct" />
                </div>
                <div class="span4 ">
                    <label style="float: right">@Html.CheckBox("displayProduct", false, new { @class = "cbcheck", @onchange = "ChangeDisplayProduct()" }) Hide not display product</label>
                </div>
            </div>
            <div class="row-fluid overflow-auto tb-cateDetail" style="height: 380px">
                <input type="hidden" name="selectedProduct" value="" />
                 <table class="table table-bordered table-fix tbl-selected krmtable" data-height="380">
                    <tr>
                        <th>Position</th>
                        <th>Product Id</th>
                        <th>Name</th>
                    </tr>
                    <tbody id="tproducts">
                        @Html.Raw(@ViewBag.dgvProducts)

                        @* @foreach (var item in (List<tblKRWSuperCategoryProduct>)@ViewBag.dgvProducts)
                    {
                        var product = _db.tblProducts.Find(item.ProductID);
                        var style = "";
                        if (!product.Display) { style = "color:gray"; }
                        <tr>
                            <td style= "@style" >@item.productOrder</td>
                            <td style= "@style">@item.ProductID</td>
                            <td style= "@style" >@product.ProductName</td>
                        </tr>

                    }*@
                    </tbody>
                </table>
            </div>
            <div class="row-fluid">
                <div class="span6">
                    <input type="button" id="RemoveProduct" name="" value="Remove Product" class=" btn btn-danger" />
                    <input type="button" name="" onclick="OpenProducts()" value="Add Product" class=" btn btn-primary" />
                </div>
                <div class="span6 text-right">
                    <input type="button" id="RemovePosition" name="" value="Remove Position" class=" btn btn-danger" />
                </div>
            </div>
        </div>
    </div>
    <div class="row-fluid">
        <div class="span4">
        </div>
        <div class="span8 text-right " style="padding-top: 10px">
            <input type="button" name="" class="btn btn-danger" value="Reload" onclick="ChangeData()" />
            <input type="button" name="" class="btn btn-primary" value="View History" onclick="OpenHistory()" />
            <input type="submit" name="" class="btn btn-success" value="Save" />
        </div>
    </div>
</form>
